package com.md.rps.service;

import com.md.rps.mybatis.interfaces.I_REGISTER;
import com.md.rps.mybatis.model.REGISTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Service
public class RegisterOperator {

    @Autowired
    private I_REGISTER i_register;

    public List<REGISTER> getRegisterByDept(int deptId) {
        return i_register.getRegisterByDept(deptId);
    }

    public List<REGISTER> getUserRegister(int userId) {
        return i_register.getUserRegister(userId);
    }

    public int getMaxOrder(int doctorId, String time, int timeOfDay) {
        return i_register.getMaxOrder(doctorId,time,timeOfDay);
    }

    public int called(int id) {
        return i_register.called(id);
    }

    // 挂号和重新排号，需要多线程处理，线程池

    public Integer addRegister(REGISTER register) {
        Integer num = 0;
        RegisterThread registerThread = new RegisterThread(i_register,register);
        FutureTask<Integer> result = new FutureTask<>(registerThread);
        new Thread(result).start();
        try {
            num = result.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return num;
    }

    public int reCall(int id, int newOrder) {
        return i_register.reCall(id,newOrder);
    }
}
